package com.cdc.toolbars;

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.content.res.AppCompatResources;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.cdc.taskhandler.R;

public class ToolBar3Activity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setTheme(R.style.BaseTheme);
        setContentView(R.layout.activity_tool_bar3);
        setToolBar();
    }

    private void setToolBar() {
        Toolbar toolbar = findViewById(R.id.toolBar);
        TextView title = findViewById(R.id.toolbar_title);
        setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_36dp);//设置导航栏图标
        title.setText("自定义标题");
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            //控制toolbar的title是否显示，默认显示app label
            actionBar.setDisplayShowTitleEnabled(false);
            //控制返回按钮是否显示
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeButtonEnabled(true); //设置返回键可用
        }
        if (toolbar != null) {
            toolbar.setOverflowIcon(AppCompatResources.getDrawable(this, R.drawable.ic_view_comfy_black_24dp));

            toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
        }
    }



}
